import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';


class TableAndLaunchUrlPage extends StatelessWidget {
  const TableAndLaunchUrlPage({super.key});

  final String url = "https://www.pgyer.com/tRKq8G";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text("Flutter demo")),
        body: Column(
          children: [
            Container(
              color: Colors.white,
              width: double.infinity,
              padding: const EdgeInsets.symmetric(horizontal: 10),
              child: SingleChildScrollView(
                scrollDirection: Axis.horizontal,
                child: Container(
                  constraints: BoxConstraints(
                      minWidth: MediaQuery.of(context).size.width, minHeight: 60),
                  padding: const EdgeInsets.only(bottom: 10),
                  color: Colors.transparent,
                  // width: double.infinity,
                  child: Table(
                    defaultColumnWidth: const IntrinsicColumnWidth(),
                    children: [
                    TableRow(children: [
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 200,
                        ),
                        color: Colors.red,
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      )),
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 200,
                        ),
                        color: Colors.red[400],
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      )),
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 100,
                        ),
                        color: Colors.red[300],
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      )),
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 200,
                        ),
                        color: Colors.red[200],
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      )),
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 50,
                        ),
                        color: Colors.red[100],
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      )),
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 100,
                        ),
                        color: Colors.blue[400],
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      )),
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 300,
                        ),
                        color: Colors.blue[300],
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      )),
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 200,
                        ),
                        color: Colors.blue[200],
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      )),
                      TableCell(
                          child: Container(
                        constraints: const BoxConstraints(
                          minWidth: 200,
                        ),
                        color: Colors.red[100],
                        height: 40,
                        child: const Center(
                          child: Text(
                            "flutter TableCell宽度",
                            textAlign: TextAlign.center,
                          ),
                        ),
                      ))
                    ]
                  )
                ]
              ),
            ),
          )
        ),
        Container(
          padding: const EdgeInsets.all(12),
          child: Center(
            child: ElevatedButton(
              onPressed: () async {
                await launchUrl(
                  Uri.parse(url),
                  mode: LaunchMode.externalApplication
                );
              },
              child: const Text("打开url"),
            ),
          ),
        )
        ],
      )
    );
  }
}
